Ext.ns('journal.home');

// {{{
journal.home.PreferenceExplorerPanel = Ext.extend(Ext.tree.TreePanel, (function() {

    //var logger = journal.LoggerFactory.getLogger("journal.PreferenceExplorerPanel");

    return {
        // configurables
        // anything what is here can be configured from outside

        // {{{

        initComponent : function() {

            //  var filter = new Ext.tree.TreeFilter(this);
            journal.home.PreferenceExplorerPanel.filter = new Ext.ux.tree.TreeFilterX(this);

            var treeLoader = new Ext.tree.TreeLoader({
                dataUrl : 'home?action=getPreference',
                listeners : {
                    beforeload : function(treeLoader, node) {
                        this.baseParams.nodeId = node.id;
                    },
                    loadexception : function() {
                        alert('loadexception');
                    },
                    load : function() {
                        this.root.childNodes[0].select();
                    }.createDelegate(this)
                }
            });

            var rootNode = new Ext.tree.AsyncTreeNode({
                id : 'b-0',
                text : 'Root',
                expanded : true,
                editable : false,
                expandable : true
            });

            journal.home.PreferenceExplorerPanel.filter = new Ext.ux.tree.TreeFilterX(this);

            // hard coded config - cannot be changed from outside
            var config = {
                loader : treeLoader,
                root : rootNode,
                autoScroll : true,
                rootVisible : false,
                //useArrows : true,
                //iconCls : '',
                closable : false,
                enableKeyEvents : true,
                height : 400,
                tbar : {
                    id : 'preferenceExplorerToolbar',
                    height : 27,
                    items : [ 'Filter:', {
                        xtype : 'trigger',
                        triggerClass : 'x-form-clear-trigger',
                        onTriggerClick : function() {
                            this.setValue('');
                            journal.home.PreferenceExplorerPanel.filter.clear();
                        },
                        id : 'filter',
                        enableKeyEvents : true,
                        listeners : {
                            focus : function() {
                                journal.home.Main.explorerPanel.activeTab.treeEditor.cancelEdit();
                            },
                            keyup : {
                                buffer : 150,
                                fn : function(field, e) {
                                    if (Ext.EventObject.ESC == e.getKey()) {
                                        field.onTriggerClick();
                                    } else {
                                        journal.StateService.restoreFlag = true;
                                        var val = this.getRawValue();
                                        var re = new RegExp('.*' + val + '.*', 'i');
                                        journal.home.PreferenceExplorerPanel.filter.clear();
                                        journal.home.PreferenceExplorerPanel.filter.filter(re, 'text');
                                    }
                                }
                            }
                        }
                    } ]
                }
            };

            this.on('click', function() {
            });

            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));

            // call parent
            journal.home.PreferenceExplorerPanel.superclass.initComponent.apply(this, arguments);

        } // e/o function initComponent

    // }}}
    };
})()); // e/o extend

// register xtype
Ext.reg('journal.home.PreferenceExplorerPanel', journal.home.PreferenceExplorerPanel);
// }}}
